home *** CD-ROM | disk | FTP | other *** search
/ The Business Master (3rd Edition) / The Business Master (3rd Edition).iso / files / utilfile / njfind / njfind.c next >
Encoding:
C/C++ Source or Header  |  1991-12-09  |  53.6 KB  |  1,956 lines

  1.  
  2.   
  3. /* --------------------------------------------------------------------------
  4.    Nifty James' Famous File Find Utility
  5.  
  6.    Version 1.00 of 20 November 1989
  7.    Version 1.10 of 16 December 1989
  8.    Version 1.11 of  5 January  1990
  9.    Version 1.12 of 13 February 1990
  10.    Version 1.50 of 25 March    1990
  11.    Version 2.00 of  3 April    1990
  12.     Version 2.10 of 25 August   1991 
  13.  
  14.    (C) Copyright 1989, 1990, 1991 by Mike Blaszczak
  15.    All Rights Reserved.
  16.  
  17.    Written for the Microsoft C Compiler Version 6.00AX.
  18.    LINK with an increased stack size!
  19. */
  20.  
  21.  
  22. /* --------------------------------------------------------------------------
  23.    Needed #include Files
  24. */
  25.  
  26. #pragma pack(1)                           /* don't space structure members */
  27. #include <ctype.h>
  28. #include <dos.h>
  29. #include <signal.h>
  30. #include <stdio.h>
  31. #include <stdlib.h>
  32. #include <string.h>
  33. #include    <time.h>
  34.  
  35. #define  byte     unsigned char
  36. #define  word     unsigned int
  37. #define  dword    unsigned long
  38. #define  boolean  char
  39. #define  TRUE     (1==1)
  40. #define  FALSE    (!TRUE)
  41.  
  42. #define ELEMENTS(array) (sizeof(array)/sizeof(array[0]))
  43.  
  44. /* --------------------------------------------------------------------------
  45.    Structures used here
  46. */
  47.  
  48. struct   fullfilename               /* used internally to hold filenames   */
  49. {
  50.    char  filename[9];
  51.    char  fileextension[4];
  52. };
  53.  
  54.  
  55. /* This is the "local file header" for zip files.  The zip_lfh structure
  56.    preceeds each file in the ZIP file, and describes the individual files
  57.    stored there.  Note that we read one of these and then fseek() over it
  58.    by using the value in zip_lfh.csize to get the new area.
  59. */
  60.  
  61. struct   zip_lfh
  62. {
  63.    dword signature;                 /* signature, must be 0x04034B50       */
  64.    word  exversion;                 /* version needed to extract           */
  65.    word  bitflags;                  /* general purpose bit flags           */
  66.    word  compression;               /* compression method                  */
  67.    word  modtime;
  68.    word  moddate;                   /* last modification time and date     */
  69.    dword crc32;                     /* crc32 filecheck for file            */
  70.    dword csize;                     /* compressed size                     */
  71.    dword usize;                     /* uncompressed size                   */
  72.    word  fnlength;                  /* filename length                     */
  73.    word  extralength;               /* extra field length                  */
  74. };
  75.  
  76. /* This is the "local file header" for ARC files.  The arc_lfh structure
  77.    preceeds each file in the ARC file, and describes the individual files
  78.    stored there.  Note that we read one of these and then fseek() over
  79.    the compressed file by using the value arc_lfh.csize to get the new
  80.    area.
  81.  
  82.    Note that ARC and PAK files use this same structure!
  83. */
  84.  
  85. struct   arc_lfh
  86. {
  87.    byte  marker;                    /* always 01Ah                         */
  88.    byte  compression;               /* how was this file stored?           */
  89.    char  filename[13];              /* filename is always 13 long          */
  90.    dword csize;                     /* compressed size                     */
  91.    word  date;                      /* date of original file               */
  92.    word  time;                      /* time of original file               */
  93.    word  crc;                       /* sixteen-bit CRC for this file       */
  94.    dword usize;                     /* uncompressed size                   */
  95. };
  96.  
  97.  
  98. struct   lzh_lfh
  99. {
  100.    byte  unknown[7];                /* unknown area                        */
  101.    dword csize;                     /* compressed size                     */
  102.    dword usize;                     /* original size                       */
  103.    word  time;                      /* last modification of date and time  */
  104.    word  date;                      /*     of the stored file              */
  105.    byte  unknown3[2];
  106.    byte  fnlength;                  /* length of file name                 */
  107. };
  108.  
  109.  
  110. struct   zoo_lfh
  111. {
  112.    word  time;                      /* last modification of date and time  */
  113.    word  date;                      /*     of the stored file              */       
  114.    word  unknownword;
  115.    dword usize;                     /* original file size                  */
  116.    dword csize;                     /* compressed size                     */
  117.    byte  unknown[10];               /* unknown area ...                    */
  118.    char  filename[13];              /* ASCIIZ filename                     */
  119. };
  120.  
  121. struct   dwc_lfh
  122. {
  123.    char  name[13];                  /* file name                           */
  124.    dword size;                      /* original size                       */
  125.    dword time;                      /* file timestamp                      */
  126.    dword new_size;                  /* compressed size                     */
  127.    dword pos;                       /* fseek() of this file in archive     */
  128.    byte  method;                    /* compression code                    */
  129.    byte  comment_size;              /* length of file comment              */
  130.    byte  directory_size;            /* length of directory name tag        */
  131.    word  crc;                       /* file CRC value                      */
  132. };
  133.  
  134.  
  135. /* DWC files are different because they have a big archive-wide information
  136.    area that NJFIND needs to use.  This is defined in dwc_block.
  137. */
  138.  
  139. struct   dwc_block
  140. {
  141.    word  size;                      /* size of this structure              */
  142.    byte  ent_sz;                    /* size of dwc_lfh structure           */
  143.    char  header[13];                /* name of header file for listings    */
  144.    dword time;                      /* timestamp of last archive change    */
  145.    dword entries;                   /* entries in the archive              */
  146.    char  id[3];                     /* "DWC" to identify archive           */
  147. };
  148.  
  149.  
  150. /*    ARJ files are even stranger; they have their own information block
  151.    which is defined here, starting in Version 2.10.
  152. */
  153.  
  154. struct    arj_lfh
  155. {
  156.     unsigned int    wHeaderID;
  157.     unsigned int    wBasicHeaderSize;
  158.     unsigned char    bFirstHeaderSize;
  159.     unsigned char    bArchiverVersionNumber;
  160.    unsigned char  bMinimumToExtract;
  161.     unsigned char    bHostOS;
  162.     unsigned char    bARJFlags;
  163.     unsigned char    bMethod;
  164.     unsigned char    bFileType;
  165.     unsigned char    bReserved;
  166.     unsigned long    dwDateTimeStamp;
  167.     unsigned long    dwCompressedSize;
  168.     unsigned long    dwOriginalSize;
  169.     unsigned long    dwOriginalFileCRC;
  170.     unsigned int    wEntryNamePos;
  171.     unsigned int    wFileAccessMode;
  172.     unsigned int    wHostData;
  173. };
  174.  
  175.  
  176.  
  177. /* --------------------------------------------------------------------------
  178.    Global Variables
  179. */
  180.  
  181. unsigned       result;              /* stored result of _dos_find*() calls */
  182. char           *temp;               /* temporary pointer for strings       */
  183. char           *extension;          /* pointer to file extension           */
  184. char           template[_MAX_PATH]; /* template to match files searched    */
  185. char           *inputfile;          /* pointer to wildcard name            */
  186.  
  187. struct fullfilename
  188.                tempfullname,        /* full name of file we're working on  */
  189.                matchname;           /* name to match                       */
  190.  
  191. unsigned       found =0;            /* count of found files                */
  192. unsigned long  totallength = 0L;    /* total of file lengths               */
  193.  
  194. unsigned       archivefound = 0;    /* count of found files in archves     */
  195. unsigned long  archivetotallength = 0L;
  196.                                     /* total file lengths of archive files.*/
  197.  
  198. struct zip_lfh zipworker;           /* workspace for zip files             */
  199. struct arc_lfh arcworker;           /* workspace for arc files             */
  200. struct lzh_lfh lzhworker;           /* workspace for lzh files             */
  201. struct zoo_lfh zooworker;           /* workspace for zoo files             */
  202.  
  203. boolean        searchzips = TRUE;   /* flags for options on searching      */
  204. boolean        searchlzhs = TRUE;   /*    the different archive types      */
  205. boolean        searchzoos = TRUE;
  206. boolean        searcharcs = TRUE;
  207. boolean        searchpaks = TRUE;
  208. boolean        searchdwcs = TRUE;
  209. boolean            searcharjs = TRUE;
  210.  
  211. boolean        verbose = FALSE;     /* TRUE for verbose mode               */
  212. boolean        progress = FALSE;    /* TRUE to show progress               */
  213. boolean        totalsmode = FALSE;  /* TURE for display totals             */
  214. boolean        changedrive = FALSE; /* set TRUE if user changed disks      */
  215.  
  216. boolean        broken = FALSE;      /* set true if user does CTRL+BREAK    */
  217.  
  218. boolean        alldrives = FALSE;   /* search through all drives           */
  219.  
  220. char           fiftyspaces[55];     /* a bunch of spaces for printmatch()  */
  221.  
  222. unsigned       drivecount;          /* used to change disk drives          */
  223. unsigned       newdrive;
  224. unsigned       olddrive;
  225. unsigned       lastdrive;
  226. char           newdriveletter[3];
  227.  
  228. char           drivelist[28];       /* list of drives to search            */
  229. char           *currentdrive;
  230.  
  231. char              szFileNameBuffer[4096];
  232.  
  233.  
  234. /* --------------------------------------------------------------------------
  235.    Global Constants
  236. */
  237.  
  238. const char     *fmessageread  = "Couldn't open file \"%s\" for read.\n";
  239. const char     *readbinary    = "rb";
  240. const char     *notsearching  = "Not searching %s files\n";
  241. const char     *eraseline     = "\t\t\t\t\t\t\t\t\t\r";
  242. const char     *wfi           = " was found in ";
  243. const char     *swfis         = "%s was found in %s%s";
  244.  
  245. const char *month3names[12] =
  246. {
  247.    "Jan", "Feb", "Mar", "Apr", "May", "Jun",
  248.    "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
  249. };
  250.  
  251.  
  252. /* --------------------------------------------------------------------------
  253.    ANSI-C Standard Function Prototypes
  254. */
  255.  
  256. void  processzip(char *filename, struct find_t *info);
  257. void  processpak(char *filename, struct find_t *info);
  258. void  processarc(char *filename, struct find_t *info);
  259. void  processlzh(char *filename, struct find_t *info);
  260. void  processzoo(char *filename, struct find_t *info);
  261. void  processdwc(char *filename, struct find_t *info);
  262. void    processarj(char *filename, struct find_t *info);
  263.  
  264. void  printinside(char *filename, char *archive, dword filesize, word date, word time);
  265. void  printinsidedwc(char *filename, char *archive, dword filesize, time_t date);
  266. void  printmatch(char *filename, dword filesize, word date, word time);
  267. void  printdate(word date);
  268. void  printtime(word time);
  269. int   comparenames(struct fullfilename *left, struct fullfilename *right);
  270. void  maketemplate(void);
  271. void  makefullname(struct fullfilename *ffn, char *path);
  272. void  searchdir(char *dirname);
  273. void  showusage(void);
  274. void  handleoption(char *option, boolean inenvironment);
  275. void  breakout(void);
  276. void  builddrivelist(void);
  277. void  handleenvironment(void);
  278. void  main(int argc, char *argv[]);
  279.  
  280.  
  281. /* --------------------------------------------------------------------------
  282. */
  283.  
  284. void  processzip(char *filename, struct find_t *info)
  285. {
  286.    FILE                 *zipfile;
  287.    char                 *insidefilename = NULL;
  288.    struct fullfilename  zipfullname;
  289.    char                 *temporary;
  290.  
  291. #if defined(DEBUG)
  292.    printf("processzip(\"%s\")\n", info->name);
  293. #endif
  294.  
  295.    /* if the file name doesn't match the requested template name,
  296.       return now and don't even bother opening the zip file.
  297.    */
  298.  
  299.    if (comparenames(&tempfullname, &matchname) == 0)
  300.       {
  301.       found++;
  302.       if (totalsmode == FALSE)
  303.          if (verbose == TRUE)
  304.             printmatch(filename, info->size, info->wr_date, info->wr_time);
  305.          else
  306.             printf("%s%s\n", newdriveletter, filename);
  307.  
  308.       totallength += info->size;
  309.       }
  310.  
  311.    if (searchzips == FALSE)
  312.       return;
  313.  
  314.    /* open the zip file by name and see if it was successful.
  315.    */
  316.  
  317.    zipfile = fopen(filename, readbinary);
  318.    if (zipfile == NULL)
  319.       {
  320.       fprintf(stderr, fmessageread, filename);
  321.       return;
  322.       }
  323.  
  324.    /* loop through the whole file
  325.    */
  326.  
  327.    while(!feof(zipfile))
  328.       {
  329.    /* read the local file header.
  330.       if we don't get it, break the loop.
  331.       At this same time, check it for a valid signature.
  332.    */
  333.  
  334.       if (fread(&zipworker, sizeof(struct zip_lfh), (size_t) 1, zipfile) != 1)
  335.          break;
  336.  
  337.       if (zipworker.signature != 0x04034B50)
  338.          break;
  339.  
  340.    /* free the temporary file name area
  341.       and allocate a space for the new name.
  342.       read it from the zip file.
  343.    */
  344.       insidefilename = szFileNameBuffer;
  345.  
  346.       if (fread((void *) insidefilename,  zipworker.fnlength, (size_t) 1, zipfile) != 1)
  347.          break;
  348.       insidefilename[zipworker.fnlength] = '\0';
  349.  
  350.       temporary = strrchr(insidefilename, '/');
  351.       if (temporary != NULL)
  352.          temporary++;
  353.       else
  354.          temporary = insidefilename;
  355.  
  356.       makefullname(&zipfullname, temporary);
  357.       if (comparenames(&zipfullname, &matchname) == 0)
  358.          {
  359.          archivefound++;
  360.          archivetotallength += zipworker.usize;
  361.          if (totalsmode == FALSE)
  362.             if (verbose == TRUE)
  363.                printinside(filename, temporary, zipworker.usize,
  364.                   zipworker.moddate, zipworker.modtime);
  365.             else
  366.                {
  367.                printf(swfis, temporary, newdriveletter, filename);
  368.                putchar('\n');
  369.                }
  370.          }
  371.       else
  372.          if (progress == TRUE)
  373.             printf("%s%s\t\t\r", newdriveletter, temporary);
  374.  
  375. #if defined(DEBUG)
  376.       printf("temporary = \"%s\"\n", temporary);
  377. #endif
  378.  
  379.    /* seek around the compressed file.
  380.    */
  381.       fseek(zipfile, zipworker.csize + zipworker.extralength, SEEK_CUR);
  382.  
  383.    /* at this point, the file pointer is once again at the
  384.       next local file header ...
  385.    */
  386.       }
  387.  
  388.  
  389.    if (progress == TRUE)
  390.       printf(eraseline);
  391.    fclose(zipfile);
  392.    return;
  393. }
  394.  
  395.  
  396. /* --------------------------------------------------------------------------
  397. */
  398.  
  399. void  processpak(char *filename, struct find_t *info)
  400. {
  401.    FILE                 *pakfile;
  402.    struct fullfilename  pakfullname;
  403.  
  404. #if defined(DEBUG)
  405.    printf("processpak(\"%s\")\n", info->name);
  406. #endif
  407.  
  408.    /* if the file name doesn't match the requested template name,
  409.       return now and don't even bother opening the zip file.
  410.    */
  411.  
  412.    if (comparenames(&tempfullname, &matchname) == 0)
  413.       {
  414.       found++;
  415.       if (totalsmode == FALSE)
  416.          if (verbose == TRUE)
  417.             printmatch(filename, info->size, info->wr_date, info->wr_time);
  418.          else
  419.             printf("%s%s\n", newdriveletter, filename);
  420.       totallength += info->size;
  421.       }
  422.  
  423.    if (searchpaks == FALSE)
  424.       return;
  425.  
  426.    /* open the pak file by name and see if it was successful.
  427.    */
  428.  
  429.    pakfile = fopen(filename, readbinary);
  430.    if (pakfile == NULL)
  431.       {
  432.       fprintf(stderr, fmessageread, filename);
  433.       return;
  434.       }
  435.  
  436.    /* loop through the whole file
  437.    */
  438.  
  439.    while(!feof(pakfile))
  440.       {
  441.    /* read the local file header.
  442.       if we don't get it, break the loop.
  443.    */
  444.  
  445.       if (fread(&arcworker, sizeof(struct arc_lfh), (size_t) 1, pakfile) != 1)
  446.          break;
  447.  
  448.    /* check the compression method.
  449.       if it is zero, the pak file is over.
  450.    */
  451.  
  452.       if (arcworker.compression == 0)
  453.          break;
  454.  
  455.       makefullname(&pakfullname, arcworker.filename);
  456.       if (comparenames(&pakfullname, &matchname) == 0)
  457.          {
  458.          archivefound++;
  459.          archivetotallength += arcworker.usize;
  460.          if (totalsmode == FALSE)
  461.             if (verbose == TRUE)
  462.                printinside(filename, arcworker.filename, arcworker.usize,
  463.                   arcworker.date, arcworker.time);
  464.             else
  465.                {
  466.                printf(swfis, arcworker.filename, newdriveletter, filename);
  467.                putchar('\n');
  468.                }
  469.          }
  470.       else
  471.          if (progress == TRUE)
  472.             printf("%s\t\t\r", arcworker.filename);
  473.  
  474. #if defined(DEBUG)
  475.       printf("filename = \"%s\"\n", arcworker.filename);
  476. #endif
  477.  
  478.    /* seek around the compressed file.
  479.    */
  480.       fseek(pakfile, arcworker.csize, SEEK_CUR);
  481.  
  482.    /* at this point, the file pointer is once again at the
  483.       next local file header ...
  484.    */
  485.       }
  486.  
  487.    if (progress == TRUE)
  488.       printf(eraseline);
  489.    fclose(pakfile);
  490.    return;
  491. }
  492.  
  493.  
  494. /* --------------------------------------------------------------------------
  495. */
  496.  
  497. void  processarc(char *filename, struct find_t *info)
  498. {
  499.    FILE                 *arcfile;
  500.    struct fullfilename  arcfullname;
  501.  
  502. #if defined(DEBUG)
  503.    printf("processarc(\"%s\")\n", info->name);
  504. #endif
  505.  
  506.    /* if the file name doesn't match the requested template name,
  507.       return now and don't even bother opening the zip file.
  508.    */
  509.  
  510.    if (comparenames(&tempfullname, &matchname) == 0)
  511.       {
  512.       found++;
  513.       if (totalsmode == FALSE)
  514.          if (verbose == TRUE)
  515.             printmatch(filename, info->size, info->wr_date, info->wr_time);
  516.          else
  517.             printf("%s%s\n", newdriveletter, filename);
  518.       totallength += info->size;
  519.       }
  520.  
  521.    if (searcharcs == FALSE)
  522.       return;
  523.  
  524.    /* open the arc file by name and see if it was successful.
  525.    */
  526.  
  527.    arcfile = fopen(filename, readbinary);
  528.    if (arcfile == NULL)
  529.       {
  530.       fprintf(stderr, fmessageread, filename);
  531.       return;
  532.       }
  533.  
  534.    /* loop through the whole file
  535.    */
  536.  
  537.    while(!feof(arcfile))
  538.       {
  539.    /* read the local file header.
  540.       if we don't get it, break the loop.
  541.    */
  542.  
  543.       if (fread(&arcworker, sizeof(struct arc_lfh), (size_t) 1, arcfile) != 1)
  544.          break;
  545.  
  546.    /* check the compression method.
  547.       if it is zero, the pak file is over.
  548.    */
  549.  
  550.       if (arcworker.compression == 0)
  551.          break;
  552.  
  553.       makefullname(&arcfullname, arcworker.filename);
  554.       if (comparenames(&arcfullname, &matchname) == 0)
  555.          {
  556.          archivefound++;
  557.          archivetotallength += arcworker.usize;
  558.          if (totalsmode == FALSE)
  559.             if (verbose == TRUE)
  560.                printinside(filename, arcworker.filename, arcworker.usize,
  561.                   arcworker.date, arcworker.time);
  562.             else
  563.                {
  564.                printf(swfis, arcworker.filename, newdriveletter, filename);
  565.                putchar('\n');
  566.                }
  567.          }
  568.       else
  569.          if (progress == TRUE)
  570.             printf("%s\t\t\r", arcworker.filename);
  571.  
  572. #if defined(DEBUG)
  573.       printf("filename = \"%s\"\n", arcworker.filename);
  574. #endif
  575.  
  576.    /* seek around the compressed file.
  577.    */
  578.       fseek(arcfile, arcworker.csize, SEEK_CUR);
  579.  
  580.    /* at this point, the file pointer is once again at the
  581.       next local file header ...
  582.    */
  583.       }
  584.  
  585.    if (progress == TRUE)
  586.       printf(eraseline);
  587.    fclose(arcfile);
  588.    return;
  589. }
  590.  
  591.  
  592. /* --------------------------------------------------------------------------
  593. */
  594.  
  595. void  processlzh(char *filename, struct find_t *info)
  596. {
  597.    FILE                 *lzhfile;
  598.    char                 *insidefilename = NULL;
  599.    struct fullfilename  lzhfullname;
  600.    char                 *temporary;
  601.  
  602. #if defined(DEBUG)
  603.    printf("processlzh(\"%s\")\n", info->name);
  604. #endif
  605.  
  606.    /* if the file name doesn't match the requested template name,
  607.       return now and don't even bother opening the lzh file.
  608.    */
  609.  
  610.    if (comparenames(&tempfullname, &matchname) == 0)
  611.       {
  612.       found++;
  613.       if (totalsmode == FALSE)
  614.          if (verbose == TRUE)
  615.             printmatch(filename, info->size, info->wr_date, info->wr_time);
  616.          else
  617.             printf("%s%s\n", newdriveletter, filename);
  618.       totallength += info->size;
  619.       }
  620.  
  621.    if (searchlzhs == FALSE)
  622.       return;
  623.  
  624.    /* open the lzh file by name and see if it was successful.
  625.    */
  626.  
  627.    lzhfile = fopen(filename, readbinary);
  628.    if (lzhfile == NULL)
  629.       {
  630.       fprintf(stderr, fmessageread, filename);
  631.       return;
  632.       }
  633.  
  634.    /* loop through the whole file
  635.    */
  636.  
  637.    while(!feof(lzhfile))
  638.       {
  639.    /* read the local file header.
  640.       if we don't get it, break the loop.
  641.    */
  642.  
  643.       if (fread(&lzhworker, sizeof(struct lzh_lfh), (size_t) 1, lzhfile) != 1)
  644.          break;
  645.  
  646.       insidefilename = szFileNameBuffer;
  647.  
  648.       if (fread((void *) insidefilename,  lzhworker.fnlength, (size_t) 1, lzhfile) != 1)
  649.          break;
  650.       insidefilename[lzhworker.fnlength] = '\0';
  651.  
  652.       temporary = strrchr(insidefilename, '\\');
  653.       if (temporary != NULL)
  654.          {
  655.          temporary++;
  656.          }
  657.       else
  658.          {
  659.          temporary = insidefilename;
  660.          }
  661.  
  662.       makefullname(&lzhfullname, temporary);
  663.       if (comparenames(&lzhfullname, &matchname) == 0)
  664.          {
  665.          archivefound++;
  666.          archivetotallength += lzhworker.usize;
  667.          if (totalsmode == FALSE)
  668.             if (verbose == TRUE)
  669.                printinside(filename, temporary, lzhworker.usize,
  670.                   lzhworker.date, lzhworker.time);
  671.             else
  672.                {
  673.                printf(swfis, temporary, newdriveletter, filename);
  674.                putchar('\n');
  675.                }
  676.          }
  677.       else
  678.          if (progress == TRUE)
  679.             printf("%s\t\t\r", temporary);
  680.  
  681. #if defined(DEBUG)
  682.       printf("temporary = \"%s\"\n", temporary);
  683. #endif
  684.  
  685.    /* seek around the compressed file.
  686.    */
  687.       fseek(lzhfile, lzhworker.csize+2L, SEEK_CUR);
  688.  
  689.    /* at this point, the file pointer is once again at the
  690.       next local file header ...
  691.    */
  692.       }
  693.  
  694.    if (progress == TRUE)
  695.       printf(eraseline);
  696.    fclose(lzhfile);
  697.    return;
  698. }
  699.  
  700.  
  701. /* --------------------------------------------------------------------------
  702. */
  703.  
  704. void  processzoo(char *filename, struct find_t *info)
  705. {
  706.    FILE                 *zoofile;
  707.    struct fullfilename  zoofullname;
  708.    int                  thischar;
  709.  
  710. #if defined(DEBUG)
  711.    printf("processzoo(\"%s\")\n", info->name);
  712. #endif
  713.  
  714.    /* if the file name doesn't match the requested template name,
  715.       return now and don't even bother opening the zip file.
  716.    */
  717.  
  718.    if (comparenames(&tempfullname, &matchname) == 0)
  719.       {
  720.       if (totalsmode == FALSE)
  721.          if (verbose == TRUE)
  722.             printmatch(filename, info->size, info->wr_date, info->wr_time);
  723.          else
  724.             printf("%s%s\n", filename);
  725.       found++;
  726.       totallength += info->size;
  727.       }
  728.  
  729.    if (searchzoos == FALSE)
  730.       return;
  731.  
  732.    /* open the zoo file by name and see if it was successful.
  733.    */
  734.  
  735.    zoofile = fopen(filename, readbinary);
  736.    if (zoofile == NULL)
  737.       {
  738.       fprintf(stderr, fmessageread, filename);
  739.       return;
  740.       }
  741.  
  742.    /* first, skip over the ZOO FILE message
  743.    */
  744.  
  745.    while (!feof(zoofile))
  746.       {
  747.       thischar = fgetc(zoofile);
  748.       if (thischar == 0x1A)
  749.          break;
  750.       }
  751.  
  752.    if (feof(zoofile))
  753.       {
  754.       fclose(zoofile);
  755.       return;
  756.       }
  757.  
  758.    /* skip over more header junk */
  759.  
  760.    fseek(zoofile, 38L, SEEK_CUR);
  761.  
  762.    /* loop through the whole file
  763.    */
  764.  
  765.    while(!feof(zoofile))
  766.       {
  767.    /* read the local file header.
  768.       if we don't get it, break the loop.
  769.    */
  770.  
  771.       if (fread(&zooworker, sizeof(struct zoo_lfh), (size_t) 1, zoofile) != 1)
  772.          break;
  773.  
  774.    /* check the compression method.
  775.       if it is zero, the pak file is over.
  776.    */
  777.  
  778.       if (zooworker.filename[0] == '\0')
  779.          break;
  780.  
  781.       strupr(zooworker.filename);
  782.       makefullname(&zoofullname, zooworker.filename);
  783.       if (comparenames(&zoofullname, &matchname) == 0)
  784.          {
  785.          archivefound++;
  786.          totallength += zooworker.usize;
  787.          if (totalsmode == FALSE)
  788.             if (verbose == TRUE)
  789.                printinside(filename, zooworker.filename, zooworker.usize,
  790.                   zooworker.date, zooworker.time);
  791.             else
  792.                {
  793.                printf(swfis, zooworker.filename, newdriveletter, filename);
  794.                putchar('\n');
  795.                }
  796.          }
  797.       else
  798.          if (progress == TRUE)
  799.             printf("%s\t\t\r", zooworker.filename);
  800.  
  801. #if defined(DEBUG)
  802.       printf("filename = \"%s\"\n", zooworker.filename);
  803. #endif
  804.  
  805.    /* seek around the compressed file.
  806.    */
  807.       fseek(zoofile, zooworker.csize+34L, SEEK_CUR);
  808.  
  809.    /* at this point, the file pointer is once again at the
  810.       next local file header ...
  811.    */
  812.       }
  813.  
  814.    if (progress == TRUE)
  815.       printf(eraseline);
  816.    fclose(zoofile);
  817.    return;
  818. }
  819.  
  820.  
  821. /* --------------------------------------------------------------------------
  822. */
  823.  
  824. void  processdwc(char *filename, struct find_t *info)
  825. {
  826.    char                 buff[256];
  827.    dword                entrycount;
  828.    long                 l;
  829.    int                  num;
  830.    int                  i=-1;
  831.    int                  j;
  832.    FILE                 *dwcfile;
  833.    struct dwc_block     archive_block;
  834.    struct dwc_lfh       dwc_entry;
  835.    struct fullfilename  dwcfullname;
  836.  
  837. #if defined(DEBUG)
  838.    printf("processdwc(\"%s\")\n", info->name);
  839. #endif
  840.  
  841.    /* if the file name doesn't match the requested template name,
  842.       return now and don't even bother opening the zip file.
  843.    */
  844.  
  845.    if (comparenames(&tempfullname, &matchname) == 0)
  846.       {
  847.       if (totalsmode == FALSE)
  848.          if (verbose == TRUE)
  849.             printmatch(filename, info->size, info->wr_date, info->wr_time);
  850.          else
  851.             printf("%s%s\n", filename);
  852.       found++;
  853.       totallength += info->size;
  854.       }
  855.  
  856.    if (searchzoos == FALSE)
  857.       return;
  858.  
  859.    /* open the zoo file by name and see if it was successful.
  860.    */
  861.  
  862.    dwcfile = fopen(filename, readbinary);
  863.    if (dwcfile == NULL)
  864.       {
  865.       fprintf(stderr, fmessageread, filename);
  866.       return;
  867.       }
  868.  
  869.    /* find (and read) the archive descriptor structure
  870.    */
  871.  
  872.    for (j=1; j <11 && i<0; j++)
  873.       {
  874.       if (fseek(dwcfile, (long) - (ELEMENTS(buff)*j - (j-1)*5), SEEK_END))
  875.          {
  876.          fseek(dwcfile, 0L, SEEK_SET);
  877.          }
  878.       else
  879.          {
  880.          l = ftell(dwcfile);
  881.          }
  882.  
  883.       num = fread((void *) buff, sizeof(char), ELEMENTS(buff), dwcfile);
  884.  
  885.       for (i = num-3; i>=0 && strncmp(buff+i, "DWC", 3); i--)
  886.          ;
  887.       }
  888.  
  889.    if (i<0)
  890.       {
  891.       fprintf(stderr, "NJFIND: Invalid DWC file format in file %s\n", filename);
  892.       fclose(dwcfile);
  893.       return;
  894.       }
  895.  
  896.    l += i+3;
  897.  
  898.    fseek(dwcfile, l - sizeof(archive_block), SEEK_SET);
  899.    fread((void *) &archive_block, sizeof(archive_block), 1, dwcfile);
  900.  
  901.    if (archive_block.entries > 5000 || archive_block.entries < 0)
  902.       {
  903.       fprintf(stderr, "NJFIND: Invalid DWC file format in file %s\n", filename);
  904.       fclose(dwcfile);
  905.       return;
  906.       }
  907.  
  908.    l -= ((long) archive_block.entries * archive_block.ent_sz +
  909.       archive_block.size);
  910.  
  911.    fseek(dwcfile, l, SEEK_SET);
  912.  
  913.    /* get each one   */
  914.  
  915.    for (entrycount = 0; entrycount < archive_block.entries; entrycount++)
  916.       {
  917.       fread((void *) &dwc_entry, sizeof(dwc_entry), 1, dwcfile);
  918.  
  919.       if (sizeof(dwc_entry) < archive_block.ent_sz)
  920.          fseek(dwcfile, (long) (archive_block.ent_sz - sizeof(dwc_entry)), SEEK_CUR);
  921.  
  922.       makefullname(&dwcfullname, dwc_entry.name);
  923.  
  924.       if (comparenames(&dwcfullname, &matchname) == 0)
  925.          {
  926.          archivefound++;
  927.          archivetotallength += dwc_entry.new_size;
  928.          if (totalsmode == FALSE)
  929.             if (verbose == TRUE)
  930.                {
  931.                printinsidedwc(filename, dwc_entry.name, dwc_entry.new_size,
  932.                   dwc_entry.time);
  933.                }
  934.             else
  935.                {
  936.                printf(swfis, dwc_entry.name, newdriveletter, filename);
  937.                putchar('\n');
  938.                }
  939.          }
  940.       else
  941.          if (progress == TRUE)
  942.             printf("%s%s\t\t\r", newdriveletter, dwc_entry.name);
  943.       }
  944.  
  945.  
  946.    if (progress == TRUE)
  947.       printf(eraseline);
  948.  
  949.    fclose(dwcfile);
  950.    return;
  951. }
  952.  
  953.  
  954. /* --------------------------------------------------------------------------
  955. */
  956.  
  957. void  processarj(char *pstrFileName, struct find_t *info)
  958. {
  959.    FILE                 *fARJFile;
  960.    char                        *pstrTemporary;
  961.    struct fullfilename  zipfullname;
  962.    unsigned int         wExtHeaderSize;
  963.    boolean              bSkippedHeader;
  964.    struct arj_lfh       sBlock;
  965.    int                  nNameLength;
  966.  
  967.    fARJFile = fopen(pstrFileName, "rb");
  968.    if (fARJFile == NULL)
  969.       {
  970.         fprintf(stderr, "NJFIND: Invalid ARJ file format in %s\n", pstrFileName);
  971.         fclose(fARJFile);
  972.       return;
  973.       }
  974.  
  975.    bSkippedHeader = FALSE;
  976.  
  977.    while (!feof(fARJFile))
  978.       {
  979.       fread(&sBlock, sizeof(struct arj_lfh), 1, fARJFile);
  980.  
  981.       if (sBlock.wBasicHeaderSize == 0)
  982.          continue;
  983.  
  984.       nNameLength = sBlock.wBasicHeaderSize-sizeof(struct arj_lfh)+4;
  985.  
  986.       fread(szFileNameBuffer, 1, nNameLength, fARJFile);
  987.  
  988.       fseek(fARJFile, 4L, SEEK_CUR);
  989.  
  990.       while ((wExtHeaderSize = (unsigned int) getw(fARJFile)) != 0)
  991.          {
  992.          fseek(fARJFile, wExtHeaderSize+2, SEEK_CUR);
  993.          }
  994.  
  995.       fseek(fARJFile, sBlock.dwCompressedSize, SEEK_CUR);
  996.  
  997.       if (bSkippedHeader == FALSE)
  998.          {
  999.          bSkippedHeader = TRUE;
  1000.          }
  1001.       else
  1002.          {
  1003.          pstrTemporary = strchr(szFileNameBuffer, '/');
  1004.  
  1005.          if (pstrTemporary != NULL)
  1006.             {
  1007.             pstrTemporary++;
  1008.             }
  1009.          else
  1010.             {
  1011.             pstrTemporary = szFileNameBuffer;
  1012.             }
  1013.  
  1014.          makefullname(&zipfullname, pstrTemporary);
  1015.          if (comparenames(&zipfullname, &matchname) == 0)
  1016.             {
  1017.             archivefound++;
  1018.                 archivetotallength += sBlock.dwOriginalSize;
  1019.  
  1020.                 if (totalsmode == FALSE)
  1021.                     {
  1022.                     if (verbose == TRUE)
  1023.                         {
  1024.                     printinside(pstrFileName, pstrTemporary, sBlock.dwOriginalSize,
  1025.                        (word) (sBlock.dwDateTimeStamp >> 16),
  1026.                             (word) (sBlock.dwDateTimeStamp & 0x0000FFFFL));
  1027.                         }
  1028.                 else
  1029.                    {
  1030.                     printf(swfis, szFileNameBuffer, newdriveletter, pstrFileName);
  1031.                     putchar('\n');
  1032.                     }
  1033.                 }
  1034.                 }
  1035.             else
  1036.                 {
  1037.                 if (progress == TRUE)
  1038.                     {
  1039.                     printf("%s%s\t\t\r", newdriveletter, szFileNameBuffer);
  1040.                     }
  1041.                 }
  1042.          }
  1043.       }
  1044.  
  1045.    fclose(fARJFile);
  1046.    return;
  1047. }
  1048.  
  1049.  
  1050.  
  1051. /* --------------------------------------------------------------------------
  1052. */
  1053.  
  1054. void  processnormal(char *filename, struct find_t *info)
  1055. {
  1056. #if defined(DEBUG)
  1057.    printf("processnormal(\"%s\")   ", info->name);
  1058.    printf("comparenames = %d\n", comparenames(&tempfullname, &matchname));
  1059. #endif
  1060.  
  1061.    if (comparenames(&tempfullname, &matchname) == 0)
  1062.       {
  1063.       found++;
  1064.       if (totalsmode == FALSE)
  1065.          if (verbose == TRUE)
  1066.             printmatch(filename, info->size, info->wr_date, info->wr_time);
  1067.          else
  1068.             printf("%s%s\n", newdriveletter, filename);
  1069.       totallength += info->size;
  1070.       }
  1071.    else
  1072.       if (progress == TRUE)
  1073.          printf("%s\t\t\r", info->name);
  1074.  
  1075.    return;
  1076. }
  1077.  
  1078.  
  1079. /* --------------------------------------------------------------------------
  1080.    printinside() prints out the file information from within an archive.
  1081.    This makes it different than printmatch only in that the file name
  1082.    *and* the name of the archive the file was in are printed.
  1083. */
  1084.  
  1085. void  printinside(char *filename, char *archive,
  1086.                dword filesize, word date, word time)
  1087. {
  1088.    int   count;
  1089.  
  1090.    count = strlen(filename) + 14 + strlen(archive) + strlen(newdriveletter);
  1091.    printf(swfis, archive, newdriveletter, filename);
  1092.  
  1093.    if (count > 48)
  1094.       {
  1095.       putchar('\n');
  1096.       printf("%s", fiftyspaces);
  1097.       }
  1098.    else
  1099.       while (count < 48)
  1100.          {
  1101.          putchar(' ');
  1102.          count++;
  1103.          }
  1104.  
  1105.    printf("%8lu ", filesize);
  1106.    printdate(date);
  1107.    printtime(time);
  1108.    putchar('\n');
  1109.  
  1110.    return;
  1111. }
  1112.  
  1113.  
  1114.  
  1115. /* --------------------------------------------------------------------------
  1116.    printinsidedwc() prints out the file information from within a DWC
  1117.     archive.  DWC archives are a little different because they store
  1118.     the date and time stamp for each file in the Unix-like "localtime()"
  1119.     format.
  1120.  
  1121.     For this function, then, we've repleaced the printdate() and
  1122.     printtime() calls with slightly different code.
  1123. */
  1124.  
  1125. void  printinsidedwc(char *filename, char *archive,
  1126.                 dword filesize, time_t date)
  1127. {
  1128.    int   count;
  1129.     struct tm *filetime;
  1130.  
  1131.     filetime = localtime(&date);
  1132.  
  1133.    count = strlen(filename) + 14 + strlen(archive) + strlen(newdriveletter);
  1134.    printf(swfis, archive, newdriveletter, filename);
  1135.  
  1136.    if (count > 48)
  1137.       {
  1138.       putchar('\n');
  1139.       printf("%s", fiftyspaces);
  1140.       }
  1141.    else
  1142.       while (count < 48)
  1143.          {
  1144.          putchar(' ');
  1145.          count++;
  1146.          }
  1147.  
  1148.    printf("%8lu ", filesize);
  1149.  
  1150.     printf("%02d-%s-%d  ", filetime->tm_mday, month3names[filetime->tm_mon],
  1151.         filetime->tm_year);
  1152.  
  1153.     printf("%2.2d:%2.2d:%2.2d\n", filetime->tm_hour, filetime->tm_min,
  1154.         filetime->tm_sec);
  1155.  
  1156.     return;
  1157. }
  1158.  
  1159.  
  1160.  
  1161. /* --------------------------------------------------------------------------
  1162. */
  1163.  
  1164. void    printinsidearj(char *filename, char *archive, dword filesize, dword date, dword time)
  1165. {
  1166.    int   count;
  1167.  
  1168.    count = strlen(filename) + 14 + strlen(archive) + strlen(newdriveletter);
  1169.    printf(swfis, archive, newdriveletter, filename);
  1170.  
  1171.     if (count > 48)
  1172.         {
  1173.         putchar('\n');
  1174.         printf("%s", fiftyspaces);
  1175.         }
  1176.     else
  1177.         {
  1178.         while (count < 48)
  1179.             {
  1180.             putchar(' ');
  1181.             count++;
  1182.             }
  1183.         }
  1184.  
  1185.     printf("%8lu ", filesize);
  1186.     printdate((word) (date >> 16));
  1187.     printtime((word) (time & 0x0000FFFFL));
  1188.     putchar('\n');
  1189.     return;
  1190. }
  1191.  
  1192.  
  1193. /* --------------------------------------------------------------------------
  1194.    printmatch() prints out the file's information.  It does this all in a
  1195.    neat, tidy way.  The width of 50 characters for the file name is imposed
  1196.    because for eleven characters of a date, eight characters for a time,
  1197.    one character for a space, and nine characters for a file size.
  1198. */
  1199.  
  1200. void  printmatch(char *filename, dword filesize, word date, word time)
  1201. {
  1202.    int count;
  1203.  
  1204.    count = strlen(filename)+strlen(newdriveletter);
  1205.    printf("%s%s", newdriveletter, filename);
  1206.  
  1207.    if (count > 48)
  1208.       {
  1209.       putchar('\n');
  1210.       printf("%s", fiftyspaces);
  1211.       }
  1212.    else
  1213.       while (count < 48)
  1214.          {
  1215.          putchar(' ');
  1216.          count++;
  1217.          }
  1218.  
  1219.    printf("%8lu ", filesize);
  1220.    printdate(date);
  1221.    printtime(time);
  1222.    putchar('\n');
  1223.  
  1224.    return;
  1225. }
  1226.  
  1227. /* --------------------------------------------------------------------------
  1228.    printdate() accepts a word of the DOS date and prints it out in
  1229.    the format "DD-MMM-CC".  MMM is a three-letter name for the month.
  1230. */
  1231.  
  1232. void  printdate(word date)
  1233. {
  1234.    printf("%02d-%s-%d  ", date & 0x001F,
  1235.       month3names[((date >> 5) & 0x000F) -1], 1980+(date >> 9));
  1236.  
  1237.    return;
  1238. }
  1239.  
  1240.  
  1241. /* --------------------------------------------------------------------------
  1242.    printtime() accepts the DOS-format for the time as a word and
  1243.    prints out the time in the format "HH:MM:SS".  Note that the
  1244.    time is in twenty-four hour format.
  1245. */
  1246.  
  1247. void  printtime(word time)
  1248. {
  1249.    printf("%2.2d:%2.2d:%2.2d", 
  1250.       time >> 11, (time >> 5) & 0x003F, (time & 0x001F) << 1);
  1251.  
  1252.    return;
  1253. }
  1254.  
  1255.  
  1256. /* --------------------------------------------------------------------------
  1257.    This function compares two fill file name structures.  It ignores
  1258.    question marks during the comparison, so it will match filenames that
  1259.    have expanded wildcards.  This routine will return a zero if the files
  1260.    are equivalent (or match by wildcard), and will return a one if the
  1261.    files names are not comparable.
  1262. */
  1263.  
  1264. int   comparenames(struct fullfilename *left, struct fullfilename *right)
  1265. {
  1266.    register char  *source;                /* working pointers for compare  */
  1267.    register char  *dest;
  1268.  
  1269.    source = left->filename;
  1270.    dest   = right->filename;
  1271.  
  1272.    while(*source && *dest)
  1273.       {
  1274.       if (*source != '?' && *dest != '?')
  1275.          if (*source != *dest)
  1276.             return 1;               /* not equal!  */
  1277.       source++;
  1278.       dest++;
  1279.       }
  1280.  
  1281.    /* code added version 1.11 */
  1282.  
  1283.    if (*source == '\0' && *dest != '\0')
  1284.       return 1;
  1285.  
  1286.    /* end code added version 1.11   */
  1287.  
  1288.    source = left->fileextension;
  1289.    dest   = right->fileextension;
  1290.  
  1291.    while(*source && *dest)
  1292.       {
  1293.       if (*source != '?' && *dest != '?')       /* skip questionmarks   */
  1294.          if (*source != *dest)
  1295.             return 1;               /* not equal!  */
  1296.       source++;
  1297.       dest++;
  1298.       }
  1299.  
  1300.    /* code added version 1.11 */
  1301.  
  1302.    if (*source == '\0' && *dest != '\0')
  1303.       return 1;
  1304.  
  1305.    /* end code added version 1.11   */
  1306.  
  1307.    return 0;                        /* zero indicates success  */
  1308. }
  1309.  
  1310.  
  1311. /* --------------------------------------------------------------------------
  1312.    maketemplate() takes inputfile[] and expands all the asterisks to
  1313.    question marks.  This is done once, first, so that the checkmatch()
  1314.    routine can more quickly and efficiently check for matches in file
  1315.    names.
  1316. */
  1317.  
  1318. void  maketemplate()
  1319. {
  1320.    register char  *source = inputfile; /* pointers for copying data  */
  1321.    register char  *dest = template;
  1322.    int   count = 0;                    /* count of template length   */
  1323.    int   inextension = 0;              /* set after we get a .       */
  1324.  
  1325.    *dest++ = '\\';
  1326.  
  1327.    while(*source != '\0' && count < 13 && inextension < 4)
  1328.       {
  1329.       if (*source != '*')
  1330.          {
  1331.          *dest++ = *source;
  1332.          count++;
  1333.          if (count == 9 || *source == '.')
  1334.             inextension++;
  1335.          source++;
  1336.          }
  1337.       else
  1338.          {
  1339.          if (inextension != 0)
  1340.             {
  1341.             for ( ; inextension<4; inextension++)
  1342.                *dest++ = '?';
  1343.             *dest = '\0';
  1344.             break;
  1345.             }
  1346.          else
  1347.             {
  1348.             for ( ; count<8; count++)
  1349.                *dest++ = '?';
  1350.             *dest++ = '.';
  1351.             inextension = 1;
  1352.             source++;
  1353.             if (*source == '.')
  1354.                source++;
  1355.             }
  1356.          }
  1357.       }
  1358.  
  1359.    *dest = '\0';
  1360.    return;
  1361. }
  1362.  
  1363.  
  1364. /* --------------------------------------------------------------------------
  1365.    makefullname() accepts a pointer to a DOS path name and a pointer to
  1366.    a fullfilename structure.  makefullname() puts the file name from
  1367.    the path into the fullfilename structure and returns.
  1368. */
  1369.  
  1370. void  makefullname(struct fullfilename *ffn, char *path)
  1371. {
  1372.    register char  *source;
  1373.    register char  *dest;
  1374.    int            counter;
  1375.  
  1376.    source = strrchr(path, '\\');
  1377.    if (source == NULL)
  1378.       source = path;
  1379.    else
  1380.       source++;
  1381.  
  1382.    for (dest = ffn->filename, counter = 0; *source && counter<8; counter++)
  1383.       if (*source == '.')
  1384.          *dest++ = ' ';
  1385.       else
  1386.          *dest++ = *source++;
  1387.  
  1388.    *dest = '\0';
  1389.    if (*source != '\0')
  1390.       source++;
  1391.  
  1392.    for (dest = ffn->fileextension, counter = 0; counter<3; counter++)
  1393.       if (*source == '\0')
  1394.          *dest++ = ' ';
  1395.       else
  1396.          *dest++ = *source++;
  1397.  
  1398.    *dest = '\0';
  1399.  
  1400.    return;
  1401. }
  1402.  
  1403.  
  1404. /* --------------------------------------------------------------------------
  1405.    searchdir() accepts the name of a directory.  That name *MUST* include
  1406.    wildcards, and may include a partial filename, a full pathname, or a
  1407.    drive specification.
  1408.  
  1409.    The function will search all directories and go lower, and will call
  1410.    itself recursively if it finds any more subdirectories.  In this way,
  1411.    it traverses the subdirectory tree in an "inorder" fasion.
  1412. */
  1413.  
  1414. void searchdir(char *dirname)
  1415. {
  1416.    char           temppath[_MAX_PATH];
  1417.    char           thisfilename[_MAX_DIR+_MAX_FNAME+_MAX_EXT];
  1418.    struct find_t  dirinfo;
  1419.  
  1420.    strcpy(temppath, dirname);
  1421.    result = _dos_findfirst(temppath, _A_NORMAL | _A_SUBDIR, &dirinfo);
  1422.  
  1423.    do {
  1424.       strcpy(thisfilename, dirname);
  1425.       *(strrchr(thisfilename, '\\')+1) = '\0';
  1426.       strcat(thisfilename, dirinfo.name);
  1427. #if defined(DEBUG)
  1428.       printf("%s ", thisfilename);
  1429. #endif
  1430.  
  1431.       if ((dirinfo.attrib & _A_SUBDIR) &&
  1432.            dirinfo.name[0] != '.')
  1433.          {
  1434. #if defined(DEBUG)
  1435.          printf("(DIRECTORY) %s\n", thisfilename);
  1436. #endif
  1437.          strcat(thisfilename, "\\*.*");
  1438.          searchdir(thisfilename);
  1439.          }
  1440.       else
  1441.          {
  1442. #if defined(DEBUG)
  1443.          putchar('\n');
  1444. #endif
  1445.  
  1446.          while(broken == FALSE)
  1447.             {
  1448.             extension = strchr(thisfilename, '.');
  1449.             if (*(extension-1) == '\\')
  1450.                break;
  1451.  
  1452.             makefullname(&tempfullname, thisfilename);
  1453.  
  1454.             if (extension != NULL)
  1455.                {
  1456.                if (strcmp(extension, ".LZH") == 0)
  1457.                   {
  1458.                   processlzh(thisfilename, &dirinfo);
  1459.                   break;
  1460.                   }
  1461.  
  1462.          /* Note that we call the same routine for .PAK and .ARC.
  1463.             They have the same (basic) format!
  1464.          */
  1465.  
  1466.                if (strcmp(extension, ".PAK") == 0)
  1467.                   {
  1468.                   processpak(thisfilename, &dirinfo);
  1469.                   break;
  1470.                   }
  1471.  
  1472.                if (strcmp(extension, ".ARC") == 0)
  1473.                   {
  1474.                   processarc(thisfilename, &dirinfo);
  1475.                   break;
  1476.                   }
  1477.  
  1478.                if (strcmp(extension, ".ZOO") == 0)
  1479.                   {
  1480.                   processzoo(thisfilename, &dirinfo);
  1481.                   break;
  1482.                   }
  1483.  
  1484.                if (strcmp(extension, ".ZIP") == 0)
  1485.                   {
  1486.                   processzip(thisfilename, &dirinfo);
  1487.                   break;
  1488.                   }
  1489.  
  1490.          /* DWC was added in version 2.00 */
  1491.  
  1492.                if (strcmp(extension, ".DWC") == 0)
  1493.                   {
  1494.                   processdwc(thisfilename, &dirinfo);
  1495.                   break;
  1496.                   }
  1497.  
  1498.             /* ARJ was added in version 2.10 */
  1499.  
  1500.                     if (strcmp(extension, ".ARJ") == 0)
  1501.                         {
  1502.                         processarj(thisfilename, &dirinfo);
  1503.                         break;
  1504.                         }
  1505.                
  1506.                }
  1507.  
  1508.             processnormal(thisfilename, &dirinfo);
  1509.             break;
  1510.             }
  1511.          }
  1512.  
  1513.       result = _dos_findnext(&dirinfo);
  1514.       } while (result == 0 && broken == FALSE);
  1515.  
  1516.    if (progress == TRUE)
  1517.       printf(eraseline);
  1518.    return;
  1519. }
  1520.  
  1521.  
  1522. /* --------------------------------------------------------------------------
  1523.    showusage() is a kind of error routine.  It is called when we get confused
  1524.    parsing the command line and bail out gracefully.  This prints the
  1525.    program usage and quits.
  1526. */
  1527.  
  1528. void  showusage()
  1529. {
  1530.    fputs("Usage: NJFIND [options] <filespec>\n", stderr);
  1531.    fputs("[options] include:\n", stderr);
  1532.    fputs("\t/A - do not search *.ARC files\n", stderr);
  1533.     fputs("\t/J - do not search *.ARJ files\n", stderr);
  1534.    fputs("\t/W - do not search *.DWC files\n", stderr);
  1535.    fputs("\t/L - do not search *.LZH files\n", stderr);
  1536.    fputs("\t/P - do not search *.PAK files\n", stderr);
  1537.    fputs("\t/O - do not search *.ZOO files\n", stderr);
  1538.    fputs("\t/Z - do not search *.ZIP files\n", stderr);
  1539.    fputs("\t/N - only search normal files (combo of /W /J /O /Z /P /A /L)\n\n", stderr);
  1540.    fputs("\t/V - verbose mode; prints statistics\n", stderr);
  1541.    fputs("\t/T - totals mode; prints no found filenames\n", stderr);
  1542.    fputs("\t/D - progress display prints filenames as searched\n", stderr);
  1543.    fputs("\t/R - run search across all DOS drives\n\n", stderr);
  1544.  
  1545.    exit(1);
  1546. }
  1547.  
  1548.  
  1549. /* --------------------------------------------------------------------------
  1550.    handleoption() takes care of the options the program accepts.  since
  1551.    these are all just switches, we just tweak the boolean variables that
  1552.    represent each option.
  1553. */
  1554.  
  1555. void  handleoption(char *option, boolean inenvironment)
  1556. {
  1557.    switch(toupper(*option))
  1558.       {
  1559.       case 'N':   searchzoos =
  1560.                   searchpaks =
  1561.                   searcharcs =
  1562.                   searchlzhs =            /* normal files ...     */
  1563.                   searchzips = FALSE;
  1564.                   fprintf(stderr, notsearching, "ARC, ARJ, DWC, LZH, PAK, ZIP, or ZOO");
  1565.                   break;
  1566.  
  1567.       case 'O':   searchzoos = FALSE;     /* turn off ZOO files   */
  1568.                   fprintf(stderr, notsearching, "ZOO");
  1569.                   break;
  1570.  
  1571.    /* added code, version 2.00   */
  1572.  
  1573.       case 'W':   searchdwcs = FALSE;     /* turn off DWC files   */
  1574.                   fprintf(stderr, notsearching, "DWC");
  1575.                   break;
  1576.  
  1577.    /* end added code */
  1578.  
  1579.     /* added code, version 2.10    */
  1580.  
  1581.         case 'J':    searcharjs = FALSE;
  1582.                         fprintf(stderr, notsearching, "ARJ");
  1583.                         break;
  1584.  
  1585.     /* end added code    */
  1586.  
  1587.       case 'Z':   searchzips = FALSE;     /* turn off ZIP files   */
  1588.                   fprintf(stderr, notsearching, "ZIP");
  1589.                   break;
  1590.  
  1591.       case 'A':   searcharcs = FALSE;     /* turn off ARC files   */
  1592.                   fprintf(stderr, notsearching, "ARC");
  1593.                   break;
  1594.  
  1595.       case 'L':   searchlzhs = FALSE;
  1596.                   fprintf(stderr, notsearching, "LZH");
  1597.                   break;
  1598.  
  1599.       case 'P':   searchpaks = FALSE;
  1600.                   fprintf(stderr, notsearching, "PAK");
  1601.                   break;
  1602.  
  1603.       case 'V':   verbose = TRUE;
  1604.                   fputs("Verbose mode\n", stderr);
  1605.                   break;
  1606.  
  1607.       case 'D':   progress = TRUE;
  1608.                   fputs("Progress displays enabled\n", stderr);
  1609.                   break;
  1610.  
  1611.       case 'T':   totalsmode = TRUE;
  1612.                   fputs("Totals mode only\n", stderr);
  1613.                   break;
  1614.  
  1615.    /* added code, version 1.10   */
  1616.  
  1617.       case 'R':   alldrives = TRUE;
  1618.                   fputs("Search all drives\n", stderr);
  1619.                   break;
  1620.  
  1621.    /* end of added code          */
  1622.  
  1623.       default:    fprintf(stderr, "NJFIND: Unrecognized Option '%c'", *option);
  1624.       
  1625.    /* added code, version 2.00   */
  1626.  
  1627.                   if (inenvironment == TRUE)
  1628.                      fprintf(stderr, " in NJFIND environment variable");
  1629.                   fputc('\n', stderr);
  1630.                   fputc('\n', stderr);
  1631.  
  1632.    /* end added code */
  1633.                   showusage();
  1634.       }
  1635.  
  1636.    return;
  1637. }
  1638.  
  1639.  
  1640. /* --------------------------------------------------------------------------
  1641.    builddrivelist() sets drivelist to an ASCII string of the drive
  1642.    letters that are valid on this system.  drivelist will only contain
  1643.    the identifiers of hard disk drives (with the media type 0xF8.)
  1644.    This function was added for Version 1.10.  This function was changed
  1645.     with Version 2.10 to accomodate DOS 5.0.
  1646. */
  1647.  
  1648. void builddrivelist()
  1649. {
  1650.    union REGS     inregs;
  1651.    struct SREGS   segregs;
  1652.  
  1653.    unsigned int   far *walker;
  1654.    unsigned int   far *newwalker;
  1655.    unsigned int   far *nextone_off;
  1656.    unsigned int   far *nextone_seg;
  1657.    char  far *media_type;
  1658.    char  *dest;
  1659.  
  1660.    dest = drivelist;
  1661.    *dest = '\0';
  1662.  
  1663.    inregs.h.ah = 0x52;
  1664.    int86x(0x21, &inregs, &inregs, &segregs);
  1665.  
  1666.    FP_OFF(newwalker) = inregs.x.bx;
  1667.    FP_SEG(newwalker) = segregs.es;
  1668.  
  1669.    FP_OFF(walker) = newwalker[0];
  1670.    FP_SEG(walker) = newwalker[1];
  1671.  
  1672.    while(1)
  1673.       {
  1674.  
  1675.       if (_osmajor == 2)
  1676.          {
  1677.          media_type = (char far *) walker + 0x16;
  1678.          nextone_off = walker + 0x0C;
  1679.          nextone_seg = walker + 0x0D;
  1680.          }
  1681.       else if (_osmajor == 3)
  1682.          {
  1683.          media_type = (char far *) walker + 0x16;
  1684.          nextone_off = walker + 0x0C;
  1685.          nextone_seg = walker + 0x0D;
  1686.          }
  1687.       else if (_osmajor == 4 || _osmajor == 5)
  1688.          {
  1689.          media_type = (char far *) walker + 0x17;
  1690.          nextone_off = (unsigned int far *) ((char far *) walker + 0x19);
  1691.          nextone_seg = (unsigned int far *) ((char far *) walker + 0x1B);
  1692.          }
  1693.  
  1694.       if ((*media_type & 0x00FF) == 0xF8)
  1695.          {
  1696.          *dest++ = (char) *walker + 'A';
  1697.          *dest = '\0';
  1698.          }
  1699.  
  1700.       FP_OFF(walker) = *nextone_off;
  1701.       FP_SEG(walker) = *nextone_seg;
  1702.  
  1703.       if ((*walker & 0x00FF) > 26)
  1704.          break;
  1705.  
  1706.       if (FP_OFF(walker) == 0xFFFF)
  1707.          break;
  1708.       }
  1709.  
  1710.    return;
  1711. }
  1712.  
  1713.  
  1714. /* --------------------------------------------------------------------------
  1715.    The breakout() function handles the SIGINT signal for the program.
  1716.    Here, we simply set a flag so that the working loop will terminate
  1717.    and return.  This allows us to leave neatly, by resetting the
  1718.    current drive and printing out our totals.  (That doesn't take very
  1719.    long and should not be much of an annoyance to the user.)
  1720. */
  1721.  
  1722. void  breakout()
  1723. {
  1724.    signal(SIGINT, SIG_IGN);
  1725.    signal(SIGINT, breakout);
  1726.  
  1727.    putchar('\n');
  1728.    broken = TRUE;
  1729.  
  1730.    return;
  1731. }
  1732.  
  1733.  
  1734. /* --------------------------------------------------------------------------
  1735.    handleenvironment() takes care of looking at the environment to
  1736.    find NJFIND settings.  If such an entry is found, it is parsed by
  1737.    running pointers through it and calling handleoption().
  1738.  
  1739.    This function is new for Version 2.00.
  1740. */
  1741.  
  1742. void handleenvironment()
  1743. {
  1744.    char *environment;
  1745.    char *walker;
  1746.    char *destination;
  1747.    char copy[10];
  1748.    int  len;
  1749.  
  1750.    environment = getenv("NJFIND");
  1751.    if (environment == NULL)
  1752.       return;
  1753.  
  1754. #if defined(DEBUG)
  1755.    printf("NJFIND found!\n");
  1756. #endif
  1757.  
  1758.    walker = environment;
  1759.  
  1760.    while (*walker != '\0')
  1761.       {
  1762.       while (isspace(*walker))
  1763.          {
  1764.          walker++;
  1765.          }
  1766.  
  1767.       if (*walker == '\0')
  1768.          break;
  1769.  
  1770.       destination = copy;
  1771.       len = 0;
  1772.  
  1773.       while (!isspace(*walker) && *walker != '\0')
  1774.          {
  1775.          *destination++ = *walker++;
  1776.          *destination = '\0';
  1777.  
  1778.          if (++len == ELEMENTS(copy))
  1779.             {
  1780.             fputs("NJFIND: option too long in environment\n", stderr);
  1781.             exit(1);
  1782.             }
  1783.          }
  1784.  
  1785.       if (copy[0] == '/' || copy[0] == '-')
  1786.          handleoption(copy+1, TRUE);
  1787.       else
  1788.          {
  1789.          fputs("NJFIND: only options supported in environment\n", stderr);
  1790.          exit(1);
  1791.          }
  1792.  
  1793.       }
  1794.  
  1795.    return;
  1796. }
  1797.  
  1798.  
  1799. /* --------------------------------------------------------------------------
  1800.    The Main Thang.
  1801. */
  1802.  
  1803. void main(int argc, char *argv[])
  1804. {
  1805.    int   argcounter;
  1806.    char  *userfilespec;
  1807.  
  1808.    signal(SIGINT, breakout);
  1809.  
  1810.    for (argcounter = 0; argcounter < 50; argcounter++)
  1811.       fiftyspaces[argcounter] = ' ';
  1812.    fiftyspaces[argcounter] = '\0';
  1813.  
  1814.    fputs("Nifty James' File Finder\n", stderr);
  1815.    fputs("Version 2.15/ASP of 9 December, 1991\n", stderr);
  1816.    fputs("(C) Copyright 1989, 1990, 1991 by Mike Blaszczak\n\n", stderr);
  1817.  
  1818.    builddrivelist();
  1819.  
  1820.    if (argc < 2)
  1821.         {
  1822.       showusage();
  1823.         }
  1824.  
  1825.    userfilespec = NULL;
  1826.    for (argcounter = 1; argcounter<argc; argcounter++)
  1827.         {
  1828.       if (argv[argcounter][0] == '/' || argv[argcounter][0] == '-')
  1829.             {
  1830.          handleoption(argv[argcounter]+1, FALSE);
  1831.             }
  1832.       else
  1833.             {
  1834.          if (userfilespec == NULL)
  1835.                 {
  1836.             userfilespec = argv[argcounter];
  1837.                 }
  1838.          else
  1839.             {
  1840.             fputs("Only one filespec allowed!\n\n", stderr);
  1841.             exit(1);
  1842.             }
  1843.             }
  1844.         }
  1845.  
  1846.    handleenvironment();
  1847.  
  1848.    /* moved from handleoption in version 2.00   */
  1849.  
  1850.    fputc('\n', stderr);
  1851.  
  1852.    /* end of moved code */
  1853.  
  1854.    _dos_getdrive(&olddrive);
  1855.    newdriveletter[0] = '\0';
  1856.  
  1857.    if (userfilespec == NULL)
  1858.       {
  1859.       userfilespec = "X:\\*.*";
  1860.       userfilespec[0] = (char) olddrive + 'A';
  1861.       drivelist[0] = userfilespec[0];
  1862.       drivelist[1] = '\0';
  1863.       }
  1864.    else
  1865.       if (alldrives == FALSE)
  1866.          {
  1867.          if (userfilespec[1] == ':')
  1868.             {
  1869.             *userfilespec = (char) toupper(*userfilespec);
  1870.             newdrive = (unsigned) (*userfilespec - 'A' +1);
  1871.             _dos_setdrive(newdrive, &drivecount);
  1872.             _dos_getdrive(&lastdrive);
  1873.  
  1874.             if (lastdrive != newdrive)
  1875.                {
  1876.                fprintf(stderr, "NJFIND: Invalid drive %c:.\n", *userfilespec);
  1877.                fprintf(stderr, "        Valid drives are A: to %c:\n",
  1878.                   drivelist[strlen(drivelist)-1]);
  1879.                exit(1);
  1880.                }
  1881.             else
  1882.                {
  1883.                changedrive = TRUE;
  1884.                drivelist[0] = *userfilespec;
  1885.                drivelist[1] = '\0';
  1886.                userfilespec += 2;
  1887.                }
  1888.             }
  1889.          else
  1890.             {
  1891.             drivelist[0] = (char) (olddrive + 'A' -1);
  1892.             drivelist[1] = '\0';
  1893.             }
  1894.          }
  1895.       else
  1896.          {
  1897.          changedrive = TRUE;
  1898.          if (userfilespec[1] == ':')
  1899.             userfilespec += 2;
  1900.          }
  1901.  
  1902.    inputfile = strupr(userfilespec);
  1903.    maketemplate();
  1904.    makefullname(&matchname, template);
  1905. #if defined(DEBUG)
  1906.    printf("template: %s\n", template);
  1907. #endif
  1908.  
  1909.    for (currentdrive = drivelist; *currentdrive != '\0';
  1910.             currentdrive++)
  1911.       {
  1912.       newdriveletter[0] = *currentdrive;
  1913.       newdriveletter[1] = ':';
  1914.       newdriveletter[2] = '\0';
  1915.       newdrive = (unsigned) (*currentdrive - 'A' +1);
  1916.       _dos_setdrive(newdrive, &drivecount);
  1917.       searchdir("\\*.*");
  1918.       }
  1919.  
  1920.    if (broken == TRUE)
  1921.       printf("\nNJFIND: Searching interrupted!\n\n");
  1922.  
  1923.    /* print out statistics */
  1924.  
  1925.    printf("\n   %5u file", found);
  1926.    if (found != 1)
  1927.       putchar('s');
  1928.    printf(" found.\n");
  1929.    printf("   %5u archived file", archivefound);
  1930.    if (archivefound != 1)
  1931.       putchar('s');
  1932.    printf(" found.\n");
  1933.  
  1934.    if (found != 0 && archivefound != 0)
  1935.       printf("   %5u files found in total.\n", found + archivefound);
  1936.    else
  1937.       putchar('\n');
  1938.  
  1939.    putchar('\n');
  1940.  
  1941.    if (totalsmode == TRUE || verbose == TRUE)
  1942.       {
  1943.       if (found != 0)
  1944.          printf("Found files total %lu bytes.\n", totallength);
  1945.       if (archivefound != 0)
  1946.          printf("Found archive files total %lu bytes.\n", archivetotallength);
  1947.       }
  1948.  
  1949.    if (changedrive == TRUE)
  1950.       _dos_setdrive(olddrive, &drivecount);
  1951.  
  1952.    exit(0);
  1953. }
  1954.  
  1955.  
  1956.